package com.chinasoft.movie.util;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.multipart.MultipartFile;

import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;

public class ToolUtil {
    public static Map<String,Object> videoMap=new HashMap<String,Object>();
    static{
        videoMap.put("videoUploadTime","2021-07-20 09:55:10.0");
        videoMap.put("videoMovieUrl","/img/5d02d017-3aa0-414f-bf9a-bdd3022dba7a.mp4");
        videoMap.put("videoImgUrl","/img/0ee22cbf-7258-476a-ab23-f2b56665258f.jpg");
        videoMap.put("videoTitle","9猫和老鼠");
        videoMap.put("videoId","25");

    }

    public static String getFileSuffixName(String  name){
        String s[]=name.split("\\.");
        String str=s[s.length-1];//后缀名
        return str;
    }

    public static String FormetFileSize(long fileS) {
        DecimalFormat df = new DecimalFormat("#.00");
        String fileSizeString = "";
        if (fileS < 1024) {
            fileSizeString = df.format((double) fileS) + "B";
        } else if (fileS < 1048576) {
            fileSizeString = df.format((double) fileS / 1024) + "K";
        } else if (fileS < 1073741824) {
            fileSizeString = df.format((double) fileS / 1048576) + "M";
        } else {
            fileSizeString = df.format((double) fileS / 1073741824) + "G";
        }
        return fileSizeString;
    }

    public static String [] spaceInfo(){
        // 当前文件系统类
        FileSystemView fsv = FileSystemView.getFileSystemView();
        // 列出所有windows 磁盘
        File[] fs = File.listRoots();
        // 显示磁盘卷标
        String a = "总大小:";
        String b = "剩余空间:";
        for (int i = 0; i < fs.length; i++) {
           String str=fsv.getSystemDisplayName(fs[i]);
            //System.out.println(str);
            if(str.equals("Data (D:)")){
                System.out.println(str);
                 a+= FormetFileSize(fs[i].getTotalSpace());
                 b+=FormetFileSize(fs[i].getFreeSpace());
                break;
            }

            //System.out.print("总大小" + FormetFileSize(fs[i].getTotalSpace()));
            //System.out.println("剩余" + FormetFileSize(fs[i].getFreeSpace()));
//            if(fsv.getSystemDisplayName(fs[i]).equals("Data (D:)")){
//                 a=FormetFileSize(fs[i].getTotalSpace());
//                 b=FormetFileSize(fs[i].getFreeSpace());
//                break;
//            }
            //System.out.println(a);
            //System.out.println(b);
        }
        return new String[]{a,b};
        }




    public static void main(String[] args) {
        //连接本地的 Redis 服务
        //RedisProperties.Jedis jedis = new Jedis("localhost");
        RedisProperties.Jedis jedis=new RedisProperties.Jedis();
        System.out.println("连接成功");
        //查看服务是否运行
        System.out.println("服务正在运行: "+jedis);

    }




}

//    select * from  tb_user order by USER_ID desc
//
//    INSERT INTO
//
//    tb_user(USER_NAME,USER_AGE,USER_SEX)
//
//    VALUES
//
//            ('kfc',22,'男'),
//
//('kfc1',24,'男');
//
//    INSERT INTO
//    tb_user (USER_NAME,USER_AGE,USER_SEX)
//    select 'nba',45,'男' from dual union all
//    select 'nbn',34,'女' from dual;
//
//<insert id="bindRight" parameterType="java.util.List">
//    INSERT INTO T_P_USER_MODUEL (USER_ID, MODUEL_ID)
//		<foreach collection="list" item="item" index="index" separator=" UNION ALL ">
//    SELECT #{item.userId}, #{item.moduelId} FROM DUAL
//	    	</foreach>
//	    </insert>
